import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue2 from '@vitejs/plugin-vue2'
// https://vitejs.dev/config/
export default ({ mode }) => defineConfig({
  base: loadEnv(mode, process.cwd()).VITE_APP_BASE_PATH, //部署应用的子路径 -读取配置文件的变量
  plugins: [
    vue2(),
    legacy({
      targets: ['ie >= 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime']
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions: ['.mjs', '.js', '.mts', '.ts', '.vue'],
  },
  server: {
    host: '0.0.0.0',
    port: '2024',
    open: true,
    fs: {
      strict: true,
    },
    proxy: {
      '/abc': 'http://192.168.0.101:8080/',// 本地测试可以如此设置代理后端地址
    },
  },
})
